export const getApiBaseUrl = () => {
  const protocol = window.location.protocol;
  let apiBaseUrl = {
    dynamicConfig: `${protocol}${process.env.VUE_APP_DINAMIC_CONFIG_API_HOST}`,
  };

  return apiBaseUrl;
};

/**
 * 整合，获取query参数值
 * @param {Object} vm vue实例
 * @param {String} key 所需参数
 */
export function getQuery(vm, key) {
  return vm.$route
    ? getQuerystring(key) || getRouteQuery(vm, key) || ""
    : getQuerystring(key) || "";
}
/**
 * 获取查询字符值
 * @param {String} key
 */
export function getQuerystring(key) {
  const url = new URL(window.location.href);
  return url.searchParams.get(key);
}

/**
 * 获取路由query参数值
 * @param {Object} vm vue实例
 * @param {String} key 所需参数
 */
export function getRouteQuery(vm, key) {
  const params = vm.$route.query;
  return params[key];
}
